package name.panitz.mobile;
import javax.microedition.lcdui.*;
public class MovableObject{
  int x=0;
  int y=0;
  double dX=1;
  double dY=2;
  int width=2;
  int height=2;
  MovableObject(int x,int y,double dX,double dY,int w,int h){
    this.x=x;
    this.y=y;
    this.dX=dX;
    this.dY=dY;
    this.width=w;
    this.height=h;
  }

  public void move(){
    x=x+(int)dX;
    y=y+(int)dY;
  }

 public boolean touches(MovableObject that){
    if (this.isLeftOf(that)) return false;
    if (that.isLeftOf(this)) return false;
    if (this.isAbove(that))  return false;
    if (that.isAbove(this))  return false;
    return true;
  }

  public boolean isAbove(MovableObject that){
    return y+height<that.y;
  }
  public boolean isLeftOf(MovableObject that){
    return this.x+this.width<that.x;
  }

  public void paintMe(Graphics g){
    g.setColor(255,0,0);
    g.fillRect(x,y,width,height);
  }
}

